const BASE_URL = "http://www.pudge.wang:3080/api";
const http = {
  get(url, params) {
    if (params) {
      let str = '?';
      Object.keys(params).forEach(el => {
        str += `${el}=${params[el]}&`;
      })
      url = url + str.slice(0, -1);
    }
    return fetch(BASE_URL + url)
      .then(response => response.json())
      .then(res => {
        return res;
      })
      .catch(e => console.log(e));
  },
  post(url, data) {
    return fetch(BASE_URL + url, {
      method: "POST",
      body: JSON.stringify(data),
      headers: new Headers({
        "Content-Type": "application/json"
      })
    })
      .then(response => response.json())
      .then(res => {
        if (res.status === 0) {
          return res;
        }
      });
  }
}
export default http;